package com.cx.service.admin.outside.impl;

import javax.annotation.Resource;

import org.cx.entity.PageData;
import org.cx.util.DesUtils;
import org.cx.util.HttpsUtil;
import org.cx.util.LogInfoUtil;
import org.springframework.stereotype.Service;

import com.cx.dao.impl.ChainJKTDaoSupport;
import com.cx.service.admin.outside.OutsideManager;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service("outsideService")
public class OutsideService implements OutsideManager {
    @Resource(name = "chainJKTDaoSupport")
    private ChainJKTDaoSupport chainJKTDao;

	@Override
	public PageData getBytopOrgId(PageData pd) throws Exception {
		pd = (PageData) chainJKTDao.findForObject("outsideUserMapper.getBytopOrgId",pd);
		return pd;
	}
	
	@Override
	public PageData getBySysId(PageData pd) throws Exception {
		pd = (PageData) chainJKTDao.findForObject("outsideUserMapper.getBySysId",pd);
		return pd;
	}

	@Override
	public PageData outsideAndJktRegister(PageData pd) throws Exception {

		//DES加密
		String parameters = DesUtils.encrypt(DesUtils.DES_KEY, "{\"userName\":\""+pd.getString("userPhone")+"\",\"chainNo\":\""+pd.getString("orgNo")+"\",\"userPwd\":\""+pd.getString("userPwd")+"\"}");
		Map<String, String> pmap = new HashMap<String, String>();
		pmap.put("parameters", parameters);
		String resultDes = HttpsUtil.sendHttpsPost(pd.getString("url"), new HashMap<String, String>(), pmap, false, 10, 10);
		pd.put("resultDes",resultDes);
		return pd;
	}

	@Override
	public PageData outsideRegister(PageData pd) throws Exception {

		PageData result = (PageData) chainJKTDao.saveBackPageData("outsideUserMapper.outsideRegister",pd);
		return result;
	}

	@Override
	public PageData getJktUser(PageData pd) throws Exception {
		List<PageData> pdlist = (List<PageData> ) chainJKTDao.findForList("outsideUserMapper.getJktUser",pd);
		return pdlist.isEmpty() ? null : pdlist.get(0);
	}


}
